<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/html">
<head>
    <meta charset="UTF-8">
    <title>编辑权限</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/asset/css/oksub.css">
    <link rel="stylesheet" href="/asset/lib/zTreeStyle/zTreeStyle.css">
</head>
<body>
<div class="ok-body">
    <!--面包屑导航区域-->
    <div class="ok-body-breadcrumb">
        <span class="layui-breadcrumb">
            <a><cite>首页</cite></a>
            <a><cite>会员管理</cite></a>
            <a><cite>权限列表</cite></a>
            <a><cite>编辑权限</cite></a>
        </span>
        <a class="layui-btn layui-btn-sm" href="javascript:location.replace(location.href);" title="刷新">
            <i class="layui-icon layui-icon-refresh"></i>
        </a>
    </div>
    <!--form表单-->
    <form class="layui-form layui-form-pane ok-form" lay-filter="permissionForm">
        <div class="layui-form-item" style="display: none">
            <label class="layui-form-label">资源ID</label>
            <div class="layui-input-block">
                <input type="text" name="id" placeholder="请输入资源名称" autocomplete="off" class="layui-input" lay-verify="required">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">资源名称</label>
            <div class="layui-input-block">
                <input type="text" name="name" placeholder="请输入资源名称" autocomplete="off" class="layui-input" lay-verify="required">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">资源标识</label>
            <div class="layui-input-block">
                <input type="text" name="identification" placeholder="请输入资源标识" autocomplete="off" class="layui-input" lay-verify="required">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">资源路径</label>
            <div class="layui-input-block">
                <input type="text" name="url" placeholder="请输入资源路径" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">资源图标</label>
            <div class="layui-input-block">
                <input type="text" name="icon" placeholder="请输入资源图标" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">资源类型</label>
            <div class="layui-input-block" id="type">
                <input type="radio" name="type" value="2" title="目录">
                <input type="radio" name="type" value="0" title="菜单">
                <input type="radio" name="type" value="1" title="按钮">
            </div>
        </div>
        <div class="layui-form-item" style="display:none">
            <label class="layui-form-label">使用状态</label>
            <div class="layui-input-block" id="status">
                <input type="radio" name="status" value="1" title="启用">
                <input type="radio" name="status" value="0" title="停用">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">排序</label>
            <div class="layui-input-block">
                <input type="text" name="priority" placeholder="请输入排序号(值越大排序越靠前，1-999)" autocomplete="off" class="layui-input" lay-verify="priorityVerify">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">资源父级</label>
            <div class="layui-input-block">
                <input type="text" name="parentId" id="parentId" lay-filter="parentId" class="layui-input" lay-verify="required">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="add">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
<!--js逻辑-->
<script src="/asset/lib/layui/layui.js"></script>
<script>
    layui.config({
        base: '/asset/lib/layui/lay/'
    }).extend({
        treeSelect: 'treeSelect/treeSelect'
    });
    layui.use(["element", "form", "okLayer", "okUtils",'jquery','treeSelect'], function () {
        var form = layui.form;
        var okLayer = layui.okLayer;
        var okUtils = layui.okUtils;
        var $ = layui.$;
        var treeSelect = layui.treeSelect;
        var parent_json = eval('('+parent.json+')');;
        //初始化赋值
        $(function(){
            form.val("permissionForm", {
                "id": parent_json.id,
                "name": parent_json.name,
                "identification": parent_json.identification,
                "url": parent_json.url,
                "icon": parent_json.icon,
                "priority": parent_json.priority
            });
            if(parent_json.status == 0){
                $("#status input[value=0]").prop("checked",true);
            }else{
                $("#status input[value=1]").prop("checked",true);
            }
            if(parent_json.type == 0){
                $("#type input[value=0]").prop("checked",true);
            }else if(parent_json.type == 1){
                $("#type input[value=1]").prop("checked",true);
            }else{
                $("#type input[value=2]").prop("checked",true);
            }
            //下拉菜单树
            treeSelect.render({
                elem: '#parentId',
                data: '/sysPermission/selectOptionTree',
                type: 'get',
                placeholder: '请点击此处选择资源父级',
                search: true,
                style: {
                    folder: {
                        enable: false
                    },
                    line: {
                        enable: true
                    }
                },
                click: function(d){
                },
                success: function (d) {
                    treeSelect.checkNode('parentId', parent_json.pid);
                    treeSelect.refresh('parentId');
                }
            });
            form.render();
        });
        //正则表达式校验
        form.verify({
            priorityVerify: [/^(?!0)\d{1,3}$/, '优先级格式不正确']
        });
        //表单提交
        form.on("submit(add)", function (data) {
            okUtils.ajax("/sysPermission/editPermission", "post", data.field).done(function (response) {
                okLayer.msg.greenTick("操作成功", function () {
                    parent.layer.close(parent.layer.getFrameIndex(window.name));
                    window.parent.location.reload(); //刷新父页面
                });
            }).fail(function (error) {
                console.log(error)
            });
            return false;
        });
    });
</script>
</body>
</html>
